package com.wuxiaoqin.admin.entity;



import com.wuxiaoqin.uitls.util.RSAUtils;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.Collection;

@Data
public class SecurityAd implements UserDetails {


    //当前登录用户
    private transient Ad currentUserInfo;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }


    @SneakyThrows
    @Override
    public String getPassword() {
        //通过解密得到密码
        String password = RSAUtils.privateDecrypt(currentUserInfo.getAPassword(), RSAUtils.getPrivateKey(currentUserInfo.getAPrivatekey()));
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String encode = bCryptPasswordEncoder.encode(password);
        return encode;
    }

    @Override
    public String getUsername() {
        return currentUserInfo.getAId().toString();
    }


    // 表示判断账户是否过期
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    // 表示判断账户是否被锁定
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    // 表示凭证{密码}是否过期
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    // 表示当前用户是否可用
    @Override
    public boolean isEnabled() {
        return true;
    }


    public Ad getUmsMember() {

        return currentUserInfo;
    }
}
